<?php

class HTech_Report_Form_DateRange extends Zend_Form
{
    public function __construct() 
    {
        parent::__construct();        
        
        $this->setName('DateRange');
        
        $report = new Zend_Form_Element_Hidden('Report');
        
        $dTo = Zend_Controller_Front::getInstance()->getRequest()->getParam('DateTo');
        if(!$dTo) $dTo = date('Y-m-d');
        $dateFrom = new Zend_Form_Element_Text('DateFrom');
        $dateFrom->setLabel("From")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->getTranslator()->translate("Required field, can't be empty")))
            ->addPrefixPath('HTech_Validate', 'HTech/Validate', 'validate')
            ->addValidator('Date', true, array(
                'maxDate' => $dTo,
                'maxInclusive' => true,
                'messages' => array(
                    'msgMaxDate' => $this->getTranslator()->translate("Invalid date or date range"))));
        
        $dFrom = Zend_Controller_Front::getInstance()->getRequest()->getParam('DateFrom');
        if(!$dFrom) $dFrom = date('Y-m-d');
        $dateTo = new Zend_Form_Element_Text('DateTo');
        $dateTo->setLabel("To")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->getTranslator()->translate("Required field, can't be empty")))
            ->addPrefixPath('HTech_Validate', 'HTech/Validate', 'validate')
            ->addValidator('Date', true, array(
                'minDate' => $dFrom,
                'minInclusive' => true,
                'maxDate' => date('Y-m-d'),
                'maxInclusive' => true,
                'messages' => array(
                    'msgMinDate' => $this->getTranslator()->translate("Invalid date or date range"))));
                              
        $cols = new Zend_Form_Element_Multiselect('Columns');
        $cols->setLabel("Columns")                
            ->setAttrib('size','10')
            ->setRequired(false); 
                
        $submit = new Zend_Form_Element_Submit('Submit');
        $submit->setLabel("Submit")
            ->addDecorator(new HTech_Form_Decorator_Button(array('type' => 'submit'))); 
                                        
        $this->addElements(array($dateFrom, $dateTo, $cols, $submit, $report));
    }

}